package com.example.perftool2;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Environment;
import android.content.DialogInterface;
import android.provider.Settings;
import android.Manifest;
import android.util.Log;

import androidx.core.app.ActivityCompat;

public class PermissionTool {

    private static final int REQUEST_EXTERNAL_STORAGE = 1;
    private static String[] PERMISSIONS_STORAGE = {
            Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.WRITE_EXTERNAL_STORAGE
    };
    private boolean havePermission = false;
    private Context mContext;
    private Activity mActivity;

    public PermissionTool(Context context, Activity activity) {
        mContext = context;
        mActivity = activity;
    }

    public void checkPermission() {
        if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            //申请权限
            ActivityCompat.requestPermissions(mActivity, PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE);
        } else {
            havePermission = true;
            Log.i("swyLog", "Android 6.0以上，11以下，当前已有权限");
        }
    }
}
